package com.qs.user.ui.VM;

import android.databinding.ObservableArrayList;
import android.databinding.ObservableField;
import android.databinding.ObservableList;
import android.databinding.ViewDataBinding;
import android.support.annotation.NonNull;

import com.qs.user.BR;
import com.qs.user.R;
import com.qs.base.data.IdentifyHistoricalEntity;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.utils.StringUtils;
import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter;
import me.tatarka.bindingcollectionadapter2.ItemBinding;
import me.tatarka.bindingcollectionadapter2.OnItemBind;

/**
* 识别历史item
* @Author ltzz
* @Date 2019/8/24
*/
public class IdentifyHistoricalItemViewModel extends ItemViewModel<IdentifyHistoricalViewModel> {
    public ObservableField<IdentifyHistoricalEntity> mItemEntity = new ObservableField<>();
    //数量
    public ObservableField<String> imgNumber=new ObservableField<>("0图");

    public IdentifyHistoricalItemViewModel(@NonNull IdentifyHistoricalViewModel viewModel, IdentifyHistoricalEntity itemEntity) {
        super(viewModel);
        mItemEntity.set(itemEntity);
        imgNumber.set(itemEntity.getFiles().size()+"图");
        if (StringUtils.isTrimEmpty(itemEntity.getDate())){
            if (itemEntity.getFiles()!=null&&itemEntity.getFiles().size()>0){
                for (int i = 0; i < itemEntity.getFiles().size(); i++) {
                    observableList.add(new IdentifyHistoricalImgItemViewModel(viewModel,itemEntity.getFiles().get(i)));
                }
            }
        }
    }

    //给RecyclerView添加ObservableList
    public ObservableList<IdentifyHistoricalImgItemViewModel> observableList = new ObservableArrayList<>();
    //RecyclerView多布局添加ItemBinding
    public ItemBinding<IdentifyHistoricalImgItemViewModel> itemBinding = ItemBinding.of(new OnItemBind<IdentifyHistoricalImgItemViewModel>() {
        @Override
        public void onItemBind(ItemBinding itemBinding, int position, IdentifyHistoricalImgItemViewModel item) {
            //设置布局
            itemBinding.set(BR.viewModel, R.layout.user_identify_historical_img_item_item);
        }
    });
    //给RecyclerView添加Adpter，请使用自定义的Adapter继承BindingRecyclerViewAdapter，重写onBindBinding方法，里面有你要的Item对应的binding对象
    public BindingRecyclerViewAdapter<IdentifyHistoricalImgItemViewModel> adapter = new BindingRecyclerViewAdapter<IdentifyHistoricalImgItemViewModel>() {
        @Override
        public void onBindBinding(ViewDataBinding binding, int variableId, int layoutRes, int position, final IdentifyHistoricalImgItemViewModel item) {
            super.onBindBinding(binding, variableId, layoutRes, position, item);
        }
    };
}
